/**
 * 
 * purpose: for deep link...
 * @auth: Ning
 * date: 2009-9-26
 * 
 * */
package core.section
{
	import com.components.swfaddress.SWFAddress;
	
	public class DeepLink
	{
		//START...
	
				
				
		//get base url...
		public static function get BaseURL():String
		{
			
			 return SWFAddress.getBaseURL();
						
		}
		
		
		//set location...
		public static function setFlag(url:String,title:String = null,notCheck:Boolean = false):void
		{
			
			var currentFlag:String = SWFAddress.getValue();
			
			var index:int = currentFlag.indexOf(url);
			
			if(!notCheck)
			{
				if(index < 0)
				{
			
					SWFAddress.setValue(url);
				
					SWFAddress.setTitle(title);
											
				}else if(url == currentFlag && title)
				{
				
					SWFAddress.setTitle(title);
				
				}
			
			}else{
				
				SWFAddress.setValue(url);
				
				if(title) SWFAddress.setTitle(title);
				
			}
			
		}	
		
		
		// get url params...
		public static function getValue(url:String):Array
		{
			
			var values:String = SWFAddress.getValue();
			
			values = values.charCodeAt(0) == 47 ? values.slice(1,values.length) : values;
				
			values = values.charCodeAt(values.length - 1) == 47 ? values.slice(0,values.length -1) : values;
			
			url = url.slice(1,url.length - 1);
									
			var params:Array;
			
			var index:int = values.indexOf(url);
								
			if(index != -1)
			{
																
				values = values.slice(index + url.length,values.length);			
															
				values = values.charCodeAt(0) == 47 ? values.slice(1,values.length) : values;
				
				values = values.charCodeAt(values.length - 1) == 47 ? values.slice(0,values.length -1) : values;
																							
				params = values.split("/");
								
				params = params.length == 0 ? null : params;
								
			}
									
			return params;
			
		} 	
		
		
		
		
		//END...
	}
}